#ifndef SCENERENDERER_H_
#define SCENERENDERER_H_

#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <iostream>		
#include "IInputHandler.h"
#include "ISceneManagement.h"
#include "Camera.h"


/*
*	___ SceneRenderer Header___
*
*
***************************************************************/
namespace Scene
{

class ISceneManagement;
 
class SceneRenderer
{
	private:
 
		IInputHandler *_inputHandler;
		ISceneManagement *_sceneManagement;
		SDL_TimerID _timer;
		SDL_TimerID _timer2;
		bool _fullscreen;

		static const int	RUN_GAME_LOOP = 1;
		static const int	TIMER_100 = 2;
		
		bool _done;
		

		Uint8* _keys;
		int _relMouseX;
		int _relMouseY;
		Sint16 _displaySizeX, _displaySizeY;
		int _relMouseSummX;
		int _relMouseSummY;
		SDL_Event ev;
		static SDL_Event event;
		
		int _frame,_mytime,_timebase,_frameTime, _lastTick, _maxFrameTime, _timeEdge;

		void HandleUserEvents(SDL_Event* event);

		void MouseMoved( Sint16 xDelta, Sint16 yDelta );

		void KeyDown( Uint8 *key );

		void KeyUp( Uint8 *key );

		void Loop();

    	void PreInitScene();

    	void Init_OpenGL();
		
		void Render();
		bool RenderCameraTransformations();

		static Uint32 GameLoopTimer(Uint32 interval, void* param);
		static Uint32 TimerFunction(Uint32 interval, void* param);

		void ComputeFPS();

	protected:
		
		
		
	public:
		
		
		
		
		SceneRenderer( ISceneManagement *sManager, IInputHandler *iHandler);
		~SceneRenderer();
		void Run();

		void quit();

		void SetInputListener(IInputHandler *inputHandler);

		void SetSceneListener(ISceneManagement *sceneManager);
		
		Sint16 getDisplayWidth() const;
		Sint16 getDisplayHeight() const;
		
		void enter2DMode();
		void leave2DMode();
		void renderBitmapString( float x,  float y,  float z,  void *font,  string str) ;
};

}

#include "ISceneManagement.h"

/***************************************************************/
#endif
